<template>
  <div class="myContainer">
    <!-- 头部标题 start -->  
    <el-row class="myHeadeTitle">
      <el-col :span="18" class="myLineHeight_35px">
        维保计划管理
      </el-col>
      <el-col :span="6" class="myTextAlignRight">
        <el-button class="myBgGreen" @click="onAddValue" v-if="isShow(237)">新增</el-button>
        <!-- <el-button class="myBgGreen">导出</el-button> -->
      </el-col>
    </el-row>
    <!-- 头部标题 end -->
    <!-- 搜索部分 start -->
    <el-row :gutter="10">
      <el-col :span="6">
        <template>
          <el-cascader
            placeholder="全部项目/小区"
            :options="regionOptions"
            v-model="regionOptSelected"
            ></el-cascader>
          </el-select>
        </template>
      </el-col>
      <el-col :span="4">
        <template>
          <el-select v-model="cycleValue" clearable placeholder="请选择周期">
            <el-option
              v-for="item in cycleOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="4">
        <el-input placeholder="输入关键字进行查询" clearable v-model="kw"></el-input>
      </el-col>
      <el-col :span="3">
        <el-button class="myBgGreen" @click="onSearchKW">查询</el-button>
      </el-col>
    </el-row>
    <!-- 搜索部分 end -->
    <!-- 数据列表 start -->
    <div class="myPaddingTop_10px">
      <template>
        <el-table
          :data="tableDataList"
          border
          stripe
          v-loading="loading"
          @selection-change="handleSelectionChange"
          style="width: 100%">
          <!-- <el-table-column
            type="selection"
            width="100">
          </el-table-column> -->
          <el-table-column
            type="index"
            label="序号"
            width="100">
          </el-table-column>
          <el-table-column
            prop="id"
            width="160"
            label="计划id">
          </el-table-column>
          <el-table-column
            prop="name"
            label="计划名称">
          </el-table-column>
          <el-table-column
            width="100"
            label="当前状态">
            <template scope="scope">
              <span>{{scope.row.status | planStatusText}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="create_time"
            width="110"
            label="制定日期">
          </el-table-column>
          <el-table-column
            prop="firstplan_starttime"
            width="150"
            label="第一次任务开始日期">
          </el-table-column>
          <el-table-column
            prop="lastplan_endtime"
            width="170"
            label="最后一次任务截止日期">
          </el-table-column>
          <el-table-column
            prop="plancount"
            width="100"
            label="任务数量">
          </el-table-column>
          <el-table-column
            prop="peroid"
            width="120"
            label="计划周期(天)">
          </el-table-column>
          <el-table-column
            prop="area_name"
            label="所属小区">
          </el-table-column>
          <el-table-column
            width="100"
            label="操作">
            <template scope="scope">
              <el-button class="look" type="text" size="small" @click="getDetail(scope.row.id)">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <!-- 数据列表 end -->
    <!-- 分页控件 start -->
    <div class="block">                    
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page_num"
        :page-sizes="[10, 15]"
        :page-size="page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    <!-- 分页控件 end -->
  </div>
</template>  

<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myHeadeTitle{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    padding-bottom: 5px;
    border-bottom: 1px solid #dbdbdb;
    margin-bottom:10px; 
  }
  .myHeadeTitle:before,.myHeadeTitle:after{
    content: " ";
    display: block;
    clear: both;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top: 2px;
  }
  .myLineHeight_35px{
    line-height: 35px;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myPaddingTop_10px{
    padding-top: 10px;
  }  
  
</style>

<script>
  import { extractAreaIds } from '@/utils/misc';
  import { getRegion } from '@/utils/localstorage';
  import { getHistoryList , taskStatus} from '@/api/maintenanceplan';
  export default {
     data(){
      return{
        kw:"",
        regionOptions: [],
        regionOptSelected: [],
        cycleValue:"",
        cycleOptions:[{value: '1',label: '年度任务'},{value: '2',label: '半年任务'},{value: '3',label: '季度任务'},{value: '4',label: '月度任务'},{value: '5',label: '日常巡检'}],
        tableDataList:[],
        page_num:1,
        page_size:10,
        total:null,
        taskStatus:taskStatus,
        loading:false
      }
    },   
    components: {
        
    },
    computed: {
      areaIds() {
        return extractAreaIds(this.regionOptSelected, this.regionOptions);
      }
    },
    filters: {
      taskStatusText: function(value) {
        return taskStatus[value];
      },
      planStatusText: function(value) {
        return (value == -2)?"未启用":"启用";
      }
    },
    mounted(){
      document.title = '计划管理';
      this.regionOptions = getRegion();
      this.regionOptSelected.push(this.regionOptions[0].value,this.regionOptions[0].children[0].value,this.regionOptions[0].children[0].children[0].value);
      
      this.onGetHistoryList();
    },
    methods:{
      onGetHistoryList(){
        let vm=this;
        vm.loading=true;
        let user_id=window.localStorage.getItem("user_id"); 
        const params = {//请求列表数据是带上拉取的条数及搜索的关键词
          keyword: vm.kw,
          area_id:vm.areaIds,
          type:vm.cycleValue,
          page_num: vm.page_num,
          page_size: vm.page_size
        };
        getHistoryList(user_id, params).then(response => {
          let res = response.data;
          vm.tableDataList = res.rows;
          vm.total = res.total;
          vm.page_num = res.page_num;
          vm.page_size = res.page_size;
          vm.loading=false;
          // console.log("维保计划列表",vm.tableDataList)
        }).catch(error => {
          vm.loading=false;
          console.log(error)
        })
      },
      onSearchKW:function(){//关键词搜索
        this.onGetHistoryList();
      },
      handleSelectionChange:function(val){//全选

      },
      getDetail:function(id){//查看详细
        this.$router.push({
          path:'/wbjhglComonents',
          query: {type: 'info', id: id}
        })
      },
      handleSizeChange(val) {//每页条数控制
        this.page_size = val;
        this.onGetHistoryList();
      },
      handleCurrentChange(val) {//每页
        this.page_num = val;
        this.onGetHistoryList();
      },
      onAddValue:function(){
        this.$router.push({
          path:'/wbjhglxx',
          query: {type: 'add'}
        })
      }
    }

  }

</script>  



